home *** CD-ROM | disk | FTP | other *** search
/ Mac Action 1996 January / mac-action-07.iso / mac / Inside Action / Beatrix Potter / Peter Rabbit / MOSAIC.DXR / 00006.ls < prev    next >
Encoding:
Text File  |  1995-07-13  |  1.6 KB  |  60 lines

  1. on mouseUp
  2.   global gMosaicMap, gMosaicCount, gMosaicX, gMosaicY, gHalfTileSizeX, gHalfTileSizeY
  3.   set whichSprite to the clickOn
  4.   set newTile to findEmptyTile(whichSprite)
  5.   if newTile < 1 then
  6.     beep()
  7.   else
  8.     set the locH of sprite whichSprite to the locH of sprite (10 + newTile)
  9.     set the locV of sprite whichSprite to the locV of sprite (10 + newTile)
  10.     set swapTile to spriteToTile(whichSprite - 20)
  11.     put char swapTile of gMosaicMap into char newTile of gMosaicMap
  12.     put "X" into char swapTile of gMosaicMap
  13.     updateStage()
  14.     put gMosaicMap
  15.   end if
  16. end
  17.  
  18. on findEmptyTile whichSprite
  19.   global gMosaicMap, gMosaicCount, gMosaicX, gMosaicY, gHalfTileSizeX, gHalfTileSizeY
  20.   set foundTile to 0
  21.   set findSprite to spriteToTile(whichSprite - 20)
  22.   set s to findSprite - 1
  23.   if s > 0 then
  24.     if char s of gMosaicMap = "X" then
  25.       set foundTile to s
  26.     end if
  27.   end if
  28.   set s to findSprite + 1
  29.   if s < (gMosaicCount + 1) then
  30.     if char s of gMosaicMap = "X" then
  31.       set foundTile to s
  32.     end if
  33.   end if
  34.   set s to findSprite - 2
  35.   if s > 0 then
  36.     if char s of gMosaicMap = "X" then
  37.       set foundTile to s
  38.     end if
  39.   end if
  40.   set s to findSprite + 2
  41.   if s < (gMosaicCount + 1) then
  42.     if char s of gMosaicMap = "X" then
  43.       set foundTile to s
  44.     end if
  45.   end if
  46.   if (findSprite = 2) and (foundTile = 3) then
  47.     set foundTile to 0
  48.   end if
  49.   if (findSprite = 4) and (foundTile = 5) then
  50.     set foundTile to 0
  51.   end if
  52.   return foundTile
  53. end
  54.  
  55. on spriteToTile whichSprite
  56.   global gMosaicMap
  57.   set mappedTile to offset(numToChar(whichSprite + 64), gMosaicMap)
  58.   return mappedTile
  59. end
  60.